#ifndef PSFEventAction_h
#define PSFEventAction_h 1

#include "G4Types.hh"
#include "G4UserEventAction.hh"
#include <vector>

#include "G4UserRunAction.hh"
class PSFRun;
class G4Run;

// class PSFRunAction;

class PSFEventActionMessenger;

class PSFEventAction : public G4UserEventAction
{
public:
  PSFEventAction();
  ~PSFEventAction() override;

  void BeginOfEventAction(const G4Event *) override;
  void EndOfEventAction(const G4Event *) override;

  G4int GetEventNo();
  void SetEventVerbose(G4int);

  void AddTIR() { fNTIR += 1; };
  void AddExiting() { fNExiting += 1; };
  void AddEscapedEnd() { fEscapedEnd += 1; };
  void AddEscapedMid() { fEscapedMid += 1; };
  void AddBounce() { fBounce += 1; };
  void AddPSFCoreBounce() { fPSFCoreBounce += 1; };
  void AddClad1Bounce() { fClad1Bounce += 1; };
  void AddClad2Bounce() { fClad2Bounce += 1; };
  void AddReflected() { fReflected += 1; };
  void AddEscaped() { fEscaped += 1; };
  void AddMirror() { fMirror += 1; };
  ///////////////////////////////////////////////////////////
  void AddPEdep(G4double edep) { fPEdep += edep; }; // 统计缪子沉积能量
  void Addpphoton() { fPNPhoton += 1; }             // 统计初始光子数
  std::vector<G4double> &GetEnergy() { return fVecEnergy; };
  std::vector<G4double> &GetTime() { return fVecTime; };
  std::vector<G4int> &GetDetectorIndex() { return fVecDetectorIndex; };
  std::vector<G4int> &GetNPhoton() { return fVecNPhoton; };
  std::vector<G4double> &GetPEdep() { return fVecPEdep; };
  std::vector<G4int> &GetNPPhoton() { return fVecNPPhoton; };
  std::vector<G4double> &GetPosX() { return fVecPosX; };
  std::vector<G4double> &GetPosY() { return fVecPosY; };
  std::vector<G4double> &GetPosZ() { return fVecPosZ; };
  std::vector<G4double> &GetDirX() { return fVecDirX; };
  std::vector<G4double> &GetDirY() { return fVecDirY; };
  std::vector<G4double> &GetDirZ() { return fVecDirZ; };
  std::vector<G4double> &GetDirTheta() { return fVecDirTheta; };
  std::vector<G4double> &GetDirPhi() { return fVecDirPhi; };

  void AddCoreTIR() { fCoreTIR += 1; };
  void AddCoreR() { fCoreR += 1; };
  void AddClad1TIR() { fClad1TIR += 1; };
  void AddClad1R() { fClad1R += 1; };
  void AddCoupleR() { fCoupleR += 1; };

  void AddAbsCoreL(G4double l) { fAbsCoreL += l; };
  void AddAbsClad1L(G4double l) { fAbsClad1L += l; };

  G4double GetInitGamma() { return fInitGamma; };
  void SetInitGamma() { fInitGamma = 0; };
  G4double GetInitCoupleR() { return fInitCoupleR; };
  void SetInitCoupleR() { fInitCoupleR = 0; };
  G4double GetInitDet() { return fInitDet; };
  void SetInitDet() { fInitDet = 0; };
  G4int GetVerboseLevel() { return fVerboseLevel; };

private:
  PSFEventActionMessenger *fEventMessenger = nullptr;
  // PSFRunAction *fRunAction = nullptr;

  G4int fVerboseLevel = 0;

  G4int fMPPCCollID = 0;

  G4int fNTIR = 0;
  G4int fNExiting = 0;
  G4int fEscapedEnd = 0;
  G4int fEscapedMid = 0;
  G4int fBounce = 0;
  G4int fPSFCoreBounce = 0;
  G4int fClad1Bounce = 0;
  G4int fClad2Bounce = 0;
  G4int fReflected = 0;
  G4int fEscaped = 0;
  G4int fMirror = 0;
  //////////////////////////////////////////////////////////
  G4double fPEdep = 0.;
  G4int fPNPhoton = 0;
  G4double fFiberZ = 0.;
  std::vector<G4double> fVecEnergy;
  std::vector<G4double> fVecTime;
  std::vector<G4int> fVecDetectorIndex;
  std::vector<G4int> fVecNPhoton;
  std::vector<G4double> fVecPEdep;
  std::vector<G4int> fVecNPPhoton;
  std::vector<G4double> fVecPosX;
  std::vector<G4double> fVecPosY;
  std::vector<G4double> fVecPosZ;
  std::vector<G4double> fVecDirX;
  std::vector<G4double> fVecDirY;
  std::vector<G4double> fVecDirZ;
  std::vector<G4double> fVecDirTheta;
  std::vector<G4double> fVecDirPhi;

  G4double fCoreTIR = 0.;
  G4double fCoreR = 0.;
  G4double fClad1TIR = 0.;
  G4double fClad1R = 0.;
  G4double fCoupleR = 0.;
  G4double fAbsCoreL = 0.;
  G4double fAbsClad1L = 0.;

  G4double fInitGamma = -1.;
  G4double fInitCoupleR = -1.;
  G4double fInitDet = -1.;
};

#endif
